package com.cloud.bssp.juc.reetrantlock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @description： TODO
 * @author：weirx
 * @date：2021/12/13 16:03
 * @version：3.0
 */
public class NonFairLockTest {

    public static void main(String[] args) throws InterruptedException {
        ReentrantLock lock = new ReentrantLock();

        for (int i = 0; i < 10; i++) {
            int finalI = i;
            new Thread(() -> {
                try {
                    lock.lock();
                    System.out.println("排队" + finalI);
                } finally {
                    lock.unlock();
                }
            }).start();
        }


        TimeUnit.MILLISECONDS.sleep(10);
        new Thread(() -> {
            try {
                lock.lock();
                System.out.println();
            } finally {
                lock.unlock();
            }
        },"插队").start();
    }
}
